<template>
  <div>
    <!-- 头像资料区域 -->
    <div class="header">
      <van-image width="60" height="60" fit="cover" round :src="info.photo" />
      <h2>
        {{ info.name }}
        <br />
        <van-tag color="#fff" text-color="#009afb">{{ info.birthday }}</van-tag>
      </h2>
    </div>

    <!-- 快捷功能区域 -->
    <van-row gutter="20">
      <van-col span="8">
        <van-icon name="newspaper-o" color="#2eadff" />
        <span>我的作品</span>
      </van-col>
      <van-col span="8">
        <van-icon name="star-o" color="#ff4f31" />
        <span>我的收藏</span>
      </van-col>
      <van-col span="8">
        <van-icon name="tosend" color="#ffa893" />
        <span>阅读历史</span>
      </van-col>
    </van-row>

    <!-- cell列表 -->
    <van-cell-group>
      <van-cell icon="edit" title="编辑资料" is-link @click="$router.push('/edit')" />
      <van-cell icon="chat-o" title="小智同学" is-link />
      <van-cell icon="setting-o" title="系统设置" is-link />
      <van-cell icon="info-o" @click="logout" title="退出登录" is-link />
    </van-cell-group>
  </div>
</template>

<script>
export default {
  data() {
    return {
      // info: {},
    };
  },

  methods: {

    logout () {

      // 要删除token（删除vuex里的token和本地存储的token）
      // 打回登录页
      this.$store.commit('logout')
    }
  },

  created() {

    this.$store.dispatch('reqUserInfo')
  },

  computed: {
    // 相当于就是给state里的userInfo起了一个别名叫info
    info() {
      return this.$store.state.userInfo;
    },
  },
};
</script>

<style lang="less">
/* 头像区域 */
.header {
  height: 100px;
  background-color: #009afb;
  /* 伸缩盒子 */
  display: flex;
  /* 垂直居中 */
  align-items: center;

  .van-image {
    padding: 0px 10px;
  }

  h2 {
    font-size: 18px;
    color: #fff;
    font-weight: 400;
  }
}
/*快捷功能区域 */
.van-row {
  .van-col {
    margin: 10px 0px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;

    text-align: center;
    span {
      display: block;
      font-size: 12px;
    }
  }
}
</style>
